<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl"/>

</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="releaseList"/>
            <#include "../common/menu.ftl"/>
        </div>
        <form class="form-inline" id="searchForm" action="/travel/releaseList.do" method="post">
            <input type="hidden" name="currentPage" id="currentPage" value="1">
        </form>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">已发布游记列表</h1>
                </div>
            </div>
            <table class="table table-striped table-hover" >
                <thead>
                <tr>
                    <th>编号</th>
                    <th>标题</th>
                    <th>封面</th>
                    <th>地点</th>
                    <th>作者</th>
                    <th>发布时间</th>
                    <th>状态</th>
                    <th></th>
                </tr>
                </thead>
                <#list pageInfo.list as entity>
                    <tr>
                       <td>${entity_index + 1}</td>
                       <td>${entity.title}</td>
                       <td><img src="${entity.coverUrl}" style="width: 30px"></td>
                       <td>${entity.place.name}</td>
                       <td>${entity.author.nickName!}</td>
                       <td>${entity.releaseTime?string("yyyy-MM-dd")}</td>
                       <td>${entity.stateName!}</td>
                        <td>
                            <a role="button" class="btn btn-xs btn-default changeStatusBtn" data-id='${entity.id}' data-uid='${entity.author.id!}' data-state="1">
                                <span class="glyphicon glyphicon-pencil"></span>取消发布
                            </a>
                            <a role="button" class="btn btn-xs btn-success lookBtn" data-content='${(entity.travelContent.content)!}'>
                                <span class="glyphicon glyphicon-eye-open"></span>查看文章
                            <a role="button" class="btn btn-xs btn-danger commendBtn" data-json='${entity.json!}'data-uid='${entity.author.id!}'>
                                <span class="glyphicon glyphicon glyphicon-thumbs-up"></span>推荐
                            </a>
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>
<div class="modal fade" id="contentModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">文章内容</h4>
            </div>
            <div class="modal-body text">

            </div>

        </div>
    </div>
</div>
<#--新增游记推荐模态框-->
<div class="modal fade" id="commendModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">新增游记推荐</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="commendForm" enctype="multipart/form-data">
                    <input type="hidden" name="travel.id" />
                    <input type="hidden" name="coverUrl"/>
                    <input type="hidden" name="travel.author.id"/>
                    <div class="form-group" >
                        <label class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="img" width="100%">
                            <input type="file" class="form-control" name="file"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="schedule" onclick="WdatePicker()"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select name="type" class="form-control">
                                <option value="1">每周推荐</option>
                                <option value="2">每月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary commendSubmitBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".searchBtn").click(function () {
            $("#searchForm").submit();
        });
        $(".commendBtn").click(function () {
            var json = $(this).data("json");
            $("#commendForm input").val("");
            if (json) {
                $("#commendForm input[name='travel.id']").val(json.id);
                $("#commendForm input[name='title']").val(json.title);
                $("#commendForm input[name='coverUrl']").val(json.coverUrl);
                $("#commendForm input[name='travel.author.id']").val(json.authorId);
                $("#img").attr("src",json.coverUrl);
            }
            $("#commendModal").modal("show");
        });
        $("#file").change(function () {
            if($(this).val()){
                $("#commendForm input[name='coverUrl']").val($(this).val());
            };
        });
        $("#commendForm").ajaxForm(function (data) {
            if (data.success) {
                reload();
            }
        });
        $(".commendSubmitBtn").click(function () {
            $("#commendForm").submit();
        });
    });
</script>
<script>
    $(function () {
        //给查询按钮绑定点击事件
       $(".searchBtn").click(function () {
           //提交表单
           $("#searchForm").submit();
       });
       //发布和拒绝按钮的点击事件
       $(".changeStatusBtn").click(function () {
           //获取当前按钮绑定的自定义属性  游记的id
           var id = $(this).data("id");
           //获取当前按钮绑定的要修改成什么状态的参数值
           var state = $(this).data("state");
           //作者
           var authorId=$(this).data("uid");
           //发送请求,将游记的id和要改成的状态携带过去
           $.get("/travel/changeStatus.do",{id:id,state:state,'author.id':authorId},function(data) {
               //成功则刷新页面
               if (data.success) {
                   reload();
               }
           });
       });
        //模态框按钮的点击事件
        $(".lookBtn").click(function () {
            //获取按钮上绑定的内容,并且作为HTML填充到模态框的body
            var c = $(this).data("content");
            $(".text").html(c);
            $("#contentModal").modal("show");
        });
    });
</script>
<style>
    #contentModal img{
        width: 100%;
    }
</style>
</body>
</html>